import 'dart:js_interop';

import 'package:flutter/material.dart';
import 'package:flutter_house_manager/pages/Home/index.dart';
import 'package:flutter_house_manager/pages/Mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({super.key});

  @override
  State<TabsPage> createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  List<BottomNavigationBarItem> _getTabsBar() {
    List<BottomNavigationBarItem> list = [];
    for (var item in _tabList) {
      list.add(BottomNavigationBarItem(
        icon: Image.asset(
          item['icon'],
          width: 30,
          height: 30,
        ),
        activeIcon: Image.asset(
          item['active_icon'],
          width: 30,
          height: 30,
        ),
        label: item['label'],
      ));
    }
    return list;
  }

  //当前选中索引
  int _currentIndex = 0;
  //List 底部导航栏
  final List _tabList = [
    {
      "label": '首页',
      "icon": "assets/tabs/home_default.png",
      "active_icon": "assets/tabs/home_active.png"
    },
    {
      "label": '我的',
      "icon": "assets/tabs/my_default.png",
      "active_icon": "assets/tabs/my_active.png"
    }
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: IndexedStack(
          index: _currentIndex,
          children: const [
            HomeView(),
            MineView(),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: const Color.fromARGB(255, 1, 53, 71), // 选中项颜色
        items: _getTabsBar(),
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
